using Common.Commands;
using Common.Commands.TemplateCommands;
using Core.Domain.Model;
using Dto.ApiResponses.TemplateResponses;
using Sanelib.DataOperation;

namespace Core.Processors.TempleteProcessors
{
	public class UpdateTempleteProcessor : ICommandProcessor<UpdateTemplete>
	{
		private readonly IRepository<Templete> _templeteRepository;

		public UpdateTempleteProcessor(IRepository<Templete> templeteRepository)
		{
			_templeteRepository = templeteRepository;
		}

		public dynamic Process(UpdateTemplete command)
 		{
			var templete = _templeteRepository.GetById(command.Id);

			templete.Name = command.Name;
			templete.Value = command.Value;

		    _templeteRepository.Update(templete);

            var response = new TemplateResponse
            {
                Id = command.Id,
                Name = command.Name,
                Value = command.Value
            };

            return response;
 		}
	}
}
